<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Guardadatos;

use Zend\ModuleManager\Feature\InitProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ControllerProviderInterface;
use Zend\ModuleManager\ModuleManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\ModuleRouteListener;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

use Guardadatos\Model\Dao\CapturaDao;
use Guardadatos\Model\Entity\Captura;

class Module implements InitProviderInterface, ConfigProviderInterface, AutoloaderProviderInterface
{
    public function init(ModuleManagerInterface $mm) {
        $events = $mm->getEventManager();
        $sharedEvents = $events->getSharedManager();

        $sharedEvents->attach('Zend\Mvc\Application', 'bootstrap', array($this, 'initConfig'));
    }

    public function initConfig(MvcEvent $e) {
       
    }
    
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
		    // if we're in a namespace deeper than one level we need to fix the \ in the path
                    __NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
                ),
            ),
        );
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    /*public function onBootstrap($e)
    {
        // You may not need to do this if you're doing it elsewhere in your
        // application
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
    }*/
    
    /*public function getServiceConfig(){
        return array(
            'factories' => array(
                'Guarda\Model\CapturaDao' => function($sm){
                    $tableGateway = $sm->get('CapturaTableGateway');
                    $dao = new CapturaDao($tableGateway);
                    return $dao;
                },
                     'CapturaTableGateway' => function($sm){
                          $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                          $resultSetPrototype = new ResultSet();
                          $resultSetPrototype->setArrayObjectPrototype(new Captura());
                          return new TableGateway('CAPTURA', $dbAdapter, null, $resultSetPrototype);
                     },
             ),
        );
    }
    
    public function getControllerConfig() {
        return array(
            'factories' => array(
                'Guardadatos\Controller\Index' => function ($sm) {
                    $locator = $sm->getServiceLocator();
                    $capturaDao = $locator->get('Guarda\Model\CapturaDao');
                    $controller = new \Guardadatos\Controller\IndexController();
                    $controller->setCapturaDato($capturaDao);
                    return $controller;
                }
            )
        );
    }*/
}
